package com.aaa.controller;

import com.aaa.entity.Cinema;
import com.aaa.entity.City;
import com.aaa.service.CinemaService;
import com.aaa.service.CityService;
import com.aaa.util.DefaultMsg;
import com.aaa.util.TableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Repository
@RequestMapping("/yingting")
public class CinemaController {

    @Autowired
    private CinemaService cinemaService;
    @Autowired
    private CityService cityService;

    @RequestMapping("/toList")
    public String toList(){
        return "cinema/list";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public TableData<Cinema> listData(@RequestParam(defaultValue = "") String keyword, Integer page, Integer limit){
        TableData<Cinema> tableData = cinemaService.page(keyword, page, limit);
        return tableData;
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public DefaultMsg saveOrUpdate(Cinema cinema){
        DefaultMsg defaultMsg = cinemaService.saveOrUpdate(cinema);
        return defaultMsg;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public DefaultMsg delete(Long cid){
        DefaultMsg defaultMsg = cinemaService.delete(cid);
        return defaultMsg;
    }

    @RequestMapping("/listAllCitys")
    @ResponseBody
    public List<City> listAllCitys(){
        List<City> cities = cityService.listAll();
        return cities;
    }

    @RequestMapping("/toEdit")
    public String toEdit(){
        return "cinema/edit";
    }
}
